package com.team3.project.validator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.team3.project.exception.UserNotFoundException;
import com.team3.project.model.Users;
import com.team3.project.service.LAPService;

@Component
public class LoginValidatorImpl implements LoginValidator {

	@Autowired
	LAPService lapservice;
	
	@Override
	public Users verifyUser(String username, String password) {
		Users user = new Users();
		try {
		if(username.length() == 4){
			boolean result = true;
			for(int i = 0; i<4; i++){
				if(!Character.isDigit(username.charAt(i))){
					result = false;
				}
			}
			if(result == true){
				int id = Integer.parseInt(username);
				Users checkUser = lapservice.findByID(id);
				if(checkUser.getPassword().equals(password)){
					user = checkUser;
				}
			}
		}
		} catch (UserNotFoundException e) {
			user = new Users();
		}
		return user;
		
	}

}
